package studay.composite;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: 设计模式
 * @description: 目录
 * @author: Tom
 * @create: 2022-01-06 21:51
 **/
public class Folder extends Root{

    List<Root> folders = new ArrayList<>();

    public Folder(String name) {
        super(name);
    }

    @Override
    public void addFile(Root root) {
        folders.add(root);
    }

    @Override
    public void removeFile(Root root) {
        folders.remove(root);
    }

    @Override
    public void display(int depth) {
        StringBuilder sb = new StringBuilder();
        for (int i=0;i<depth;i++){
            sb.append("_");
        }
        System.out.println(new String(sb)+this.getName());

        for (Root r : folders){
            r.display(depth+2);
        }
    }

    public List<Root> getFolders() {
        return folders;
    }

    public void setFolders(List<Root> folders) {
        this.folders = folders;
    }

}
